<template>
  <el-dialog title="添加用户" :visible.sync="dialogVisible" width="30%"
             :before-close="close">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-form-item prop="name" label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item prop="role" label="用户角色">
        <el-select style="width:100%" v-model="form.role" placeholder="请选择用户角色">
          <el-option label="管理员" value="2"></el-option>
          <el-option label="审核员" value="1"></el-option>
          <el-option label="普通用户" value="0"></el-option>
        </el-select>
      </el-form-item>
      <!--            <el-form-item prop="nickName" label="昵称">-->
      <!--                <el-input v-model="form.nickName"></el-input>-->
      <!--            </el-form-item>-->
      <el-form-item prop="password" label="密码">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
            <el-button @click="close">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </span>
  </el-dialog>
</template>

<script lang="ts">

import {Component, Prop, Vue} from "vue-property-decorator";
import { AddUser } from "../../apis/apis";
@Component({
  name: "AddPersonDialog",
})
export default class AddPersonDialog extends Vue{

  //dialogVisible= {
    //type: Boolean,
    //default: false
  //}
  @Prop({default:false})dialogVisible!: boolean
  form={
    name: '',
    role: '',
    // nickName: '',
    password: '',
  }
  rules={
    name: { required: true, message: '请输入用户名', trigger: 'blur' },
    role: { required: true, message: '请选择用户角色', trigger: 'change' },
    // nickName: { required: true, message: '请输入昵称', trigger: 'blur' },
    password: { required: true, message: '请输入密码', trigger: 'blur' },
  }

  close():void {
    this.dialogVisible = false
    console.log("关闭成功")
  }

  //注册用户
  submit():void{
    let n = Number(this.form.role)
    console.log(n)
    console.log(this.form.name)
    console.log(this.form.password)
    AddUser(this.form.name,n ,this.form.password).then((res:any)=>
    {
      console.log(res.data)
      if(res.data.code==='200')
      {
        this.$message({
          message: '添加成功',
          type: 'success'
        })
      }
      this.dialogVisible = false
    }
    ).catch((err) =>{
      console.log(err);
   })

  }


  
}
</script>


<style lang="scss" scoped>
</style>